package com.game.manager
{
    import com.dusk.net.AssetManager;
    import com.dusk.net.AssetType;
    import com.dusk.net.AssetUrl;
    import com.game.data.constant.ConfigConst;
    import com.game.proxy.AttackDataProxy;
    import com.game.proxy.EquipProxy;
    import com.game.proxy.FurnaceProxy;
    import com.game.proxy.LevelProxy;
    import com.game.proxy.MonsterProxy;
    import com.game.proxy.ResProxy;
    import com.game.proxy.SkillProxy;
    import com.game.proxy.TaskProxy;
    
    public class ConfigManager
    {
        public function ConfigManager()
        {
            super();
        }
        
        public var skillProxy:SkillProxy;
        
        public var taskProxy:TaskProxy;
        
        public var equipProxy:EquipProxy;
        
        public var monsterProxy:MonsterProxy;
        
        public var levelProxy:LevelProxy;
        
        public var furnaceProxy:FurnaceProxy;
        
        public var resProxy:ResProxy;
        
        public var attackDataProxy:AttackDataProxy;
        
        public function initData():void
        {
            skillProxy = new SkillProxy();
            furnaceProxy = new FurnaceProxy();
            levelProxy = new LevelProxy();
            resProxy = new ResProxy();
            taskProxy = new TaskProxy();
            equipProxy = new EquipProxy();
            monsterProxy = new MonsterProxy();
            attackDataProxy = new AttackDataProxy();
            if (ConfigConst.LOAD_CONFIG_TYPE == "single")
            {
                var data:Object = AssetManager.getIns().getConfig(AssetUrl.getConfigAssetUrl("Config.json"));
                skillProxy.setConfigData(data.Skill);
                furnaceProxy.fusionItems = data.Fusion;
                furnaceProxy.makeItems = data.Make;
                levelProxy.setConfigData(data.Level);
                resProxy.setConfigData(data.Resource);
                equipProxy.setConfigData(data.Equip);
                monsterProxy.setConfigData(data.Monster);
                attackDataProxy.setConfigData(data.AttackData);
            }
            else if (ConfigConst.LOAD_CONFIG_TYPE == "multi")
            {
                var getConfig:Function = function (n:String):Object
                {
                    return AssetManager.getIns().getJSON(AssetUrl.getConfigAssetUrl(n + ".json"));
                }
                skillProxy.setConfigData(getConfig("Skill"));
                furnaceProxy.fusionItems = getConfig("Fusion");
                furnaceProxy.makeItems = getConfig("Make");
                levelProxy.setConfigData(getConfig("Level"));
                resProxy.setConfigData(getConfig("Resource"));
                equipProxy.setConfigData(getConfig("Equip"));
                monsterProxy.setConfigData(getConfig("Monster"));
                attackDataProxy.setConfigData(getConfig("AttackData"));
            }
            
        }
        
        public function loadConfig(callback:Function):void
        {
            if (ConfigConst.LOAD_CONFIG_TYPE == "single")
            {
                AssetManager.getIns().loadAsset(AssetUrl.getConfigAssetUrl("Config.json"), AssetType.CONFIG, null, initData, null, null);
            }
            else if (ConfigConst.LOAD_CONFIG_TYPE == "multi")
            {
                const arr:Array = ["Level", "Make", "Skill", "Fusion","Resource","Monster","AttackData","Equip"];
                for each(var i:String in arr)
                {
                    AssetManager.getIns().addAssetToQueue(AssetUrl.getConfigAssetUrl(i + ".json"), AssetType.JSON, null, initData, null, null);
                }
            }
            AssetManager.getIns().addCallback(callback);
            AssetManager.getIns().startLoadQueue();
        }
    }
}
